<?php
    /**
     * Transfer.php
     *
     * Created by PhpStorm.
     * author: liuml  <liumenglei0211@163.com>
     * DateTime: 2018/7/30  16:04
     */

    namespace app\wap\controller;

    use think\Config;
    use Think\Request;
    use data\service\PushMessage as PMSG;

    class Transfer extends BaseController
    {
        public function __construct()
        {
            parent::__construct();
            $this->verifySign();
        }

        public function skipUrl()
        {
            $request = Request::instance();
            $data    = $request->get();
            $info    = $data['original'];
            $this->newWchatLogin($info);
            $uid = $this->uid;
            if (empty($uid)) {
                $redirect = "https://isv.tiaze.com/admin/weixin/oauth?sub_info=gzh_" . $data['action'];
                $this->redirect($redirect); // 用户未登录
            }
            $is_member = $this->user->getSessionUserIsMember();
            if (empty($is_member)) {
                $redirect = "https://isv.tiaze.com/admin/weixin/oauth?sub_info=gzh_" . $data['action'];
                $this->redirect($redirect); // 用户未登录
            }
            if (isset($data['baseurl'])) {
                $url = $data['baseurl'];
            } else {
                if (strpos($data['action'], '@-@')) {
                    $controllerAction = str_replace('@-@', '/', $data['action']);
                    $url              = __URL__ . "/wap/" . $controllerAction;
                } else {
                    $url = Config::get('redirectUrl.' . $data['action']) ? : __URL__ . "/wap";
                }
            }

            $this->redirect(__URL($url));
        }

        /*
        // 测试获取access_token
        public function getToken()
        {
            $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx1e0dc70dec5c898c&secret=82fa26915053532f25eed14fbf2c1b6d';
            print_r(file_get_contents($url));
        }*/

        /**
         * 计划任务执行发送模板消息
         * @return bool
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         */
        public function executeSendTemp()
        {
            $pmsg = new PMSG();
            $res  = $pmsg->executeSendTemp();
            if ($res == 1) {
                die('执行成功');
            } elseif ($res == 2) {
                die('上一次请求正在执行...');
            } elseif ($res == 3) {
                die('执行失败');
            }
        }

    }

